﻿using System;
using System.Linq;
using System.Collections.Generic;
using MetroDropBox.Shared;
using System.Threading.Tasks;

namespace MetroHoo.External.Yahoo
{
    public class YahooClient : oAuthClientBase
    {
        protected YahooAuthToken yahooAccessToken;
        public YahooClient(string apiKey, string apiSecret) : base(apiKey, apiSecret) { }

        protected override void init()
        {
            passOAuthTokenByDefault = true;
            useAuthHeaderForHttpUris = false;
            useSha1SigningForHttpUris = true;
            usesAuthHeader = false;
            upperCaseUrlEncoding = true;
            useSha1Signing = true;
            getRequestTokenURL = "https://api.login.yahoo.com/oauth/v2/get_request_token";
            getRequestTokenMethod = "GET";
            getUserLoginURL = "https://api.login.yahoo.com/oauth/v2/request_auth";
            getAuthTokenURL = "https://api.login.yahoo.com/oauth/v2/get_token";
            //authPageJsTweaks = "body.style.overflowX='visible';body.style.overflowY='visible';');";
        }

/*        public override async Task<String> GetLoginUrlAsync(string redirectUrl)
        {
            var requestToken = await GetRequestTokenAsync(new Dictionary<string, string>(), redirectUrl);
            if (requestToken != null && !String.IsNullOrEmpty(requestToken.Token))
                return "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=" + requestToken.Token;
            return "";
        }*/

        protected override OAuthToken parseAuthToken(string result)
        {

            yahooAccessToken = new YahooAuthToken(result);
            return yahooAccessToken;
        }

        public async Task<String> GetLeagues()
        {
            var url = "http://fantasysports.yahooapis.com/fantasy/v2/leagues";
            var result = await httpGetForString(url, new Dictionary<string, string>());
            return result;
        }
    }
}
